from scipy.io import arff
import numpy as np
import pandas as pd

files = ["EQ", "JDT", "LC", "ML", "PDE"]

for name in files:
    data, meta = arff.loadarff(f'dataset/{name}.arff')
    df = pd.DataFrame(data)

    # 删除重复行
    df.drop_duplicates(inplace=True)

    # 填补空缺值
    df.fillna(0, inplace=True)

    # 暂时去除标记
    cls = df["class"]
    df.drop("class", axis=1, inplace=True)

    # 数据归一化，使数据值控制在[0, 1]
    df = df.apply(lambda x: (x - np.min(x)) / (np.max(x) - np.min(x)))

    # 数据标准化
    # df = df.apply(lambda x: (x - np.mean(x)) / (np.std(x)))

    # 恢复标记
    df["class"] = cls

    # 输出csv
    df.to_csv(f'output/{name}.csv', index=False)
